

*---------------------*
* 1.) Preliminaries   *
*---------------------*

/* Bring in data as received from survey firm */
*import delimited "data/inputs/Democracy.csv", ///
*       encoding(ISO-8859-1)clear
*drop in 1/1
*set more off
use "data/inputs/Democracy.dta"  

/* Drops irrelevant variables */
drop collectorid-startdate

/* Record survey date (so you can look at responses over time) */ 
gen survey_date = date(enddate, "MDY ####") 
format survey_date %td 
drop enddate

/* Drops non-consenters */
tab doyouagreetoparticipateinthisstu
keep if regexm(doyouagreetoparticipateinthisstu, "I agree")
drop doyouagreetoparticipateinthisstu 

/* Drops irrelevant variables */
drop ipaddress-customdata1

/* Drops complete non-response */
gen anyresponse = 0
foreach var of varlist whatisthehighestlevelofeducation-devicetype {
replace anyresponse = 1 if missing(`var') == 0
}
tab anyresponse
drop if anyresponse == 0
drop anyresponse



*---------------------*
* 2.) Demographics    *
*---------------------*

/* Education */
tab whatisthehighestlevelofeducation
gen education = .
replace education = 1 if regexm(whatisthehighestlevelofeducation, "Did not")
replace education = 2 if regexm(whatisthehighestlevelofeducation, "High school graduate")
replace education = 3 if regexm(whatisthehighestlevelofeducation, "Some college")
replace education = 4 if regexm(whatisthehighestlevelofeducation, "Associate")
replace education = 5 if regexm(whatisthehighestlevelofeducation, "Bachelor")
replace education = 6 if regexm(whatisthehighestlevelofeducation, "Post-graduate")

label variable education "Educational attainment"
label define educationl 1 "No high school degree", replace
label define educationl 2 "High school degree", add
label define educationl 3 "Some college", add
label define educationl 4 "Associate's degree", add
label define educationl 5 "Bachelor's degree", add
label define educationl 6 "Post-graduate degree", add
label values education educationl
drop whatisthehighestlevelofeducation

/* Year of birth */
gen year_of_birth = .
replace year_of_birth = real(inwhatyearwereyouborn) if missing(inwhatyearwereyouborn) == 0

label variable year_of_birth "Year of birth"
drop inwhatyearwereyouborn

/* Age */
gen resp_age = 2018 - year_of_birth 
replace resp_age = resp_age/10 

/* Gender */
tab iconsidermyselftobe
gen gender_pre = .
replace gender_pre = 1 if regexm(iconsidermyselftobe, "Female")
replace gender_pre = 2 if regexm(iconsidermyselftobe, "Male")

label variable gender_pre "Gender (pre-survey)"
label define gender_prel 1 "Female", replace
label define gender_prel 2 "Male", add
label values gender_pre genderl
drop iconsidermyselftobe

/* Race */
tab v14
gen race = .
replace race = 1 if regexm(v14, "Caucasian")
replace race = 2 if regexm(v14, "African-American")
replace race = 3 if regexm(v14, "Hispanic/Latino")
replace race = 4 if regexm(v14, "Asian American")
replace race = 5 if regexm(v14, "Other")

label variable race "Race"
label define racel 1 "Caucasian", replace
label define racel 2 "African-American", add
label define racel 3 "Hispanic", add
label define racel 4 "Asian", add
label define racel 5 "Other", add
label values race racel
drop v14




*---------------------*
* 3.) Partisanship    *
*---------------------*

/* Care more about partisanship of governor or president? */
tab whichofthefollowingismoreimporta
gen pres_or_gov = .
replace pres_or_gov = 1 if regexm(whichofthefollowingismoreimporta, "president")
replace pres_or_gov = 2 if regexm(whichofthefollowingismoreimporta, "governor")

label variable pres_or_gov "Prefer president or governor from your party"
label define pres_or_govl 1 "President", replace
label define pres_or_govl 2 "Governor", add
label values pres_or_gov pres_or_govl
drop whichofthefollowingismoreimporta

/* Which level of government most impactful on your everyday life  */
tab thinkingaboutelectedofficialsatd
gen most_impactful = .
replace most_impactful = 1 if regexm(thinkingaboutelectedofficialsatd, "President")
replace most_impactful = 2 if regexm(thinkingaboutelectedofficialsatd, "governor")
replace most_impactful = 3 if regexm(thinkingaboutelectedofficialsatd, "mayor")

label variable most_impactful "What level of government most impactful on everyday life"
label define most_impactfull 1 "Federal", replace
label define most_impactfull 2 "State", add
label define most_impactfull 3 "Local", add
label values most_impactful most_impactfull
drop thinkingaboutelectedofficialsatd

/* Party ID */ 
sencode generallyspeakingdoyouusual, generate(pid_root)  
sencode wouldyoucallyourselfastrong, generate(pid_strength) 
sencode doyouthinkofyourselfasclos, generate(ind_branch) 

gen party3 = . 
replace party3 = 1 if pid_root == "Democrat":pid_root
replace party3 = 2 if pid_root == "Independent":pid_root
replace party3 = 3 if pid_root == "Republican":pid_root 
tabulate party3

tab generallyspeakingdoyouusual if missing(party3)
tab wouldyoucallyourselfastrong if missing(party3)
tab wouldyoucallyourselfastrong if missing(party3)

label variable party3 "3-point partisan identifcation"
label define party3l 1 "Democrat", replace
label define party3l 2 "Independent", add
label define party3l 3 "Republican", add
label values party3 party3l

gen party7 = . 
replace party7 = 1 if pid_root == "Democrat":pid_root & pid_strength == "Strong":pid_strength   
replace party7 = 2 if pid_root == "Democrat":pid_root & pid_strength == "Not very strong":pid_strength  
replace party7 = 3 if pid_root == "Independent":pid_root & ind_branch == "Democratic":ind_branch 
replace party7 = 4 if pid_root == "Independent":pid_root & ind_branch == "Neither":ind_branch 
replace party7 = 5 if pid_root == "Independent":pid_root & ind_branch == "Republican":ind_branch 
replace party7 = 6 if pid_root == "Republican":pid_root & pid_strength == "Not very strong":pid_strength   
replace party7 = 7 if pid_root == "Republican":pid_root & pid_strength == "Strong":pid_strength   
tabulate party7

tab generallyspeakingdoyouusual if missing(party7)
tab wouldyoucallyourselfastrong if missing(party7)
tab wouldyoucallyourselfastrong if missing(party7)

label variable party7 "7-point partisan identifcation"
label define party7l 1 "Strong democrat", replace
label define party7l 2 "Not very strong democrat", add
label define party7l 3 "Lean democrat", add
label define party7l 4 "Pure independent", add
label define party7l 5 "Lean republican", add
label define party7l 6 "Not very strong republican", add
label define party7l 7 "Strong republican", add
label values party7 party7l
 
drop generallyspeakingdoyouusual pid_root wouldyoucallyourselfastrong /*
*/ pid_strength doyouthinkofyourselfasclos ind_branch

/* Dummy for Republicans (inc. leaners) */ 
gen rep = 0 
replace rep = 1 if party7 > 4 
replace rep = . if party7 == .  


*----------------------------*
* 4.) World Values Survey    *
*----------------------------*

/* encode */
sencode thefirstoneishavingastrongleader, gen(wvs1) 
sencode whatabouthavingexpertsnotgovernm, gen(wvs2) 
sencode whatabouthavingthemilitaryruleis, gen(wvs3) 
sencode whatabouthavingademocraticpoliti, gen(wvs4)

/* strong leader question */
gen strong_leader = . 
replace strong_leader = 1 if wvs1 == "Very bad way of governing the United States":wvs1 
replace strong_leader = 2 if wvs1 == "Fairly bad way of governing the United States":wvs1 
replace strong_leader = 3 if wvs1 == "Fairly good way of governing the United States":wvs1 
replace strong_leader = 4 if wvs1 == "Very good way of governing the United States":wvs1 

label variable strong_leader "WVS strong leader question"
label define wvsl 1 "Very bad", replace
label define wvsl 2 "Fairly bad", add
label define wvsl 3 "Fairly good", add
label define wvsl 4 "Very good", add
label values strong_leader wvsl

/* expert rule question */
gen expert_rule = . 
replace expert_rule = 1 if wvs2 == "Very bad way of governing the United States":wvs2 
replace expert_rule = 2 if wvs2 == "Fairly bad way of governing the United States":wvs2 
replace expert_rule = 3 if wvs2 == "Fairly good way of governing the United States":wvs2 
replace expert_rule = 4 if wvs2 == "Very good way of governing the United States":wvs2 

label variable expert_rule "WVS expert rule question"
label values expert_rule wvsl

/* military rule question */
gen military_rule  = . 
replace military_rule = 1 if wvs3 == "Very bad way of governing the United States":wvs3 
replace military_rule = 2 if wvs3 == "Fairly bad way of governing the United States":wvs3 
replace military_rule = 3 if wvs3 == "Fairly good way of governing the United States":wvs3 
replace military_rule = 4 if wvs3 == "Very good way of governing the United States":wvs3

label variable military_rule "WVS military rule question"
label values military_rule wvsl

/* reverse scale so higher values are less democratic */ 
gen antidemoc = . 
replace antidemoc = 4 if wvs4 == "Very bad way of governing the United States":wvs4
replace antidemoc = 3 if wvs4 == "Fairly bad way of governing the United States":wvs4
replace antidemoc = 2 if wvs4 == "Fairly good way of governing the United States":wvs4 
replace antidemoc = 1 if wvs4 == "Very good way of governing the United States":wvs4 

label variable antidemoc "WVS democracy question (reverse coded)"
label define wvsl2 4 "Very bad", replace
label define wvsl2 3 "Fairly bad", add
label define wvsl2 2 "Fairly good", add
label define wvsl2 1 "Very good", add
label values antidemoc wvsl2

alpha strong_leader expert_rule military_rule antidemoc, std gen(dem_index) 

/* Note: alpha is 0.58, too low for a scale, so caution */ 

label variable strong_leader "Crombach alpha of wvs questions"

drop thefirstoneishavingastrongleader whatabouthavingexpertsnotgovernm /*
*/ whatabouthavingthemilitaryruleis whatabouthavingademocraticpoliti wvs*

egen wvs_avg = rmean(strong_leader expert_rule military_rule antidemoc) 
label variable wvs_avg "Avg. value of wvs questions"  



*----------------------------*
* 5.) Experiment 1           *
*----------------------------*

/* Scenario for Experiment #1 */ 
/* Here, 1 = lobbyists, 2 = extreme agenda, 3 = gridlock */ 
sencode aâdemocraticstategovernorwantsto, generate(dscen1) 
sencode aârepublicanstategovernorwantsto, generate(rscen1) 

/* Independents randomly assigned to party and scenario */ 
/* 1 = Dem lobby, 2 = Dem extreme, 3 = Rep lobby, 4 = Rep extreme, 5 = Dem gridlock, 6 = Rep gridlock*/  
sencode v26, gen(iscen1) 
drop aâdemocraticstategovernorwantsto aârepublicanstategovernorwantsto v26

/* Attention/Manipulation Check Questions */ 
sencode wejustaskedyoutoreadabrie, gen(exp1_scenario_answer)
label variable exp1_scenario_answer "Experiment 1 manipulation check"
drop wejustaskedyoutoreadabrie 

sencode whatpartywasthegovernorfrom, gen(exp1_govparty_answer) 
label variable exp1_govparty_answer "Experiment 1 attention check"
drop whatpartywasthegovernorfrom

/* Make one variable across parties that records the treatment scenario */ 
/* Note: will not get treatment scenario for non-response */
/* Note: no way to recover treatment for non-responders from page ordering */
gen exp1_scenario = . 
replace exp1_scenario = 3 if dscen1 == 1 | rscen == 1 | iscen1 == 1 | iscen == 3 
replace exp1_scenario = 1 if dscen1 == 2 | rscen == 2 | iscen1 == 2 | iscen == 4 
replace exp1_scenario = 2 if dscen1 == 3 | rscen == 3 | iscen1 == 5 | iscen == 6 

label variable exp1_scenario  "Experiment 1 scenario treatment" 
label define exp1_scenariol 3 "Special Interests", replace
label define exp1_scenariol 1 "Polarization", add
label define exp1_scenariol 2 "Gridlock", add
label values exp1_scenario exp1_scenariol

/* Make one variable across parties that records the party */ 
/* Note: will not get treatment scenario for non-response */
/* Note: no way to recover treatment for non-responsers from page ordering */

gen exp1_govparty = 1 if missing(dscen) == 0 | /*
*/ (iscen1 == 3 | iscen == 4 | iscen == 6) 
replace exp1_govparty = 2 if missing(rscen) == 0 | /*
*/ (iscen1 == 1 | iscen == 2 | iscen == 5) 

label variable exp1_govparty  "Experiment 1 party treatment" 
label define exp1_govpartyl 1 "Democratic" 2 "Republican", replace
label values exp1_govparty exp1_govpartyl 

drop dscen* rscen* iscen*

/* Recode the DV (responses not ordered), higher values --> more support */ 
sencode ifyouhadtheopportunitytovoteinth, gen(vote1)

gen exp1_support = .  
replace exp1_support = 1 if vote1 == 2 
replace exp1_support = 2 if vote1 == 3 
replace exp1_support = 3 if vote1 == 1 
replace exp1_support = 4 if vote1 == 4 

label variable exp1_support "Experiment 1 support" 
label define exp1_supportl 4 "Definitely support", replace
label define exp1_supportl 3 "Probably support", add
label define exp1_supportl 2 "Probably oppose", add
label define exp1_supportl 1 "Definitely oppose", add
label values exp1_support exp1_supportl
drop ifyouhadtheopportunitytovoteinth vote1
 
 
 
*----------------------------*
* 6.) Experiment 2           *
*----------------------------*

/* DVs for Experiment 2 */
/* Different people see different versions (due to differences in condition wording), you then need to combine them */ 
sencode inthearticleyoujustreadwh, gen(exp2_go1) 
sencode doyouapproveofthegovernorâsappoi, gen(exp2_ap1) 
sencode isthegovernorâsappointmentofâane, gen(exp2_cwd1) 
 
sencode v36, gen(exp2_go2) 
sencode doyouapproveoftheoutgoinggoverno, gen(exp2_ap2) 
sencode istheoutgoinggovernorâsappointme, gen(exp2_cwd2) 

sencode v40, gen(exp2_go3) 
sencode doyouapprovetheoutgoinggovernorâ, gen(exp2_ap3) 
sencode istheoutgoinggovernorâsefforttoa, gen(exp2_cwd3) 

sencode v44, gen(exp2_go4) 
sencode v45, gen(exp2_ap4) 
sencode v46, gen(exp2_cwd4) 

/* Combines attention check */ 
gen exp2_attention = . 
foreach i of numlist 1/4 {
	replace exp2_attention = 1 if exp2_go`i' == "Appoint a new justice to the state Supreme Court":exp2_go`i' 
	replace exp2_attention = 2 if exp2_go`i' == "Change the budget process":exp2_go`i' 
	replace exp2_attention = 3 if exp2_go`i' == "Change the shape of congressional districts":exp2_go`i' 
	replace exp2_attention = 4 if exp2_go`i' == "Pass a new law":exp2_go`i' 
	replace exp2_attention = 5 if exp2_go`i' == "None of the above":exp2_go`i' 
} 

label variable exp2_attention  "Experiment 2 attention check" 
label define exp2_attentionl 1 "New justice", replace
label define exp2_attentionl 2 "Change budget process", add
label define exp2_attentionl 3 "Change shape of congressional district", add
label define exp2_attentionl 4 "Pass new law", add
label define exp2_attentionl 5 "None of the above", add
label values exp2_attention exp2_attentionl

/* Combines approval */ 
gen exp2_support = . 
foreach i of numlist 1/4{
	replace exp2_support = 1 if exp2_ap`i' == "Strongly disapprove":exp2_ap`i' 
	replace exp2_support = 2 if exp2_ap`i' == "Somewhat disapprove":exp2_ap`i'
	replace exp2_support = 3 if exp2_ap`i' == "Somewhat approve":exp2_ap`i'	
	replace exp2_support = 4 if exp2_ap`i' == "Strongly approve":exp2_ap`i'
}

label variable exp2_support "Experiment 2 approval" 
label define exp2_supportl 1 "Strongly disapprove", replace
label define exp2_supportl 2 "Somewhat disapprove", add
label define exp2_supportl 3 "Somewhat approve", add
label define exp2_supportl 4 "Strongly approve", add
label values exp2_support exp2_supportl

gen exp2_consistent = . 
foreach i of numlist 1/4{
	replace exp2_consistent = 1 if exp2_cwd`i' == "Completely inconsistent with democracy":exp2_cwd`i' 
	replace exp2_consistent = 2 if exp2_cwd`i' == "Mostly inconsistent with democracy":exp2_cwd`i'
	replace exp2_consistent = 3 if exp2_cwd`i' == "Mostly consistent with democracy":exp2_cwd`i'	
	replace exp2_consistent = 4 if exp2_cwd`i' == "Completely consistent with democracy":exp2_cwd`i'
}

label variable exp2_consistent "Experiment 2 consistency with democracy" 
label define exp2_consistentl 1 "Completely inconsistent", replace
label define exp2_consistentl 2 "Mostly inconsistent", add
label define exp2_consistentl 3 "Mostly consistent", add
label define exp2_consistentl 4 "Completely consistent", add
label values exp2_consistent exp2_consistentl

drop inthearticle* doyouapprove* isthegovernor* istheoutgoing* v36 v40 v44 /*
*/v45 v46 exp2_go* exp2_ap* exp2_cwd*



*--------------------------------------*
* 7.) Updating across experiments      *
*--------------------------------------*
 
 /* This is the check: do you correctly remember what just happened? */ 
gen exp2_recall = . 
foreach var of varlist youreadanewsstoryaboutagovernorw v43 v47 {
	replace exp2_recall = 1 if regexm(`var', "successfully appointed")
	replace exp2_recall = 2 if regexm(`var', "court blocked") 
	replace exp2_recall = 3 if regexm(`var', "withdrew the nomination")
}

label variable exp2_recall "Experiment 2 recall" 
label define exp2_recalll 1 "Successfully appointed", replace
label define exp2_recalll 2 "Court blocked", add
label define exp2_recalll 3 "Withdrew nomination", add
label values exp2_recall exp2_recalll

drop youreadanewsstoryaboutagovernorw v43 v47

sencode earlierweaskedyouaboutthegoverno, gen(spill1) 
sencode v48, gen(spill2) 

gen spillover = . 
foreach i of numlist 1/2{
	replace spillover = 1 if spill`i' == "Not at all likely":spill`i' 
	replace spillover = 2 if spill`i' == "Not too likely":spill`i'
	replace spillover = 3 if spill`i' == "Very likely":spill`i'
	replace spillover = 4 if spill`i' == "Extremely likely":spill`i'
}

label variable spillover "Likelihood of Success in Vignette 1" 
label define spilloverl 1 "Not at all likely", replace
label define spilloverl 2 "Not too likely", add
label define spilloverl 3 "Very likely", add
label define spilloverl 4 "Extremely likely", add
label values spillover spilloverl

drop earlierweaskedyouaboutthegoverno v48 spill1 spill2

sencode overallhowdemocraticallydoyouthi, gen(how_democ1) 
sencode v49, gen(how_democ2) 

gen how_democ = . 
foreach i of numlist 1/2{
	replace how_democ = 1 if how_democ`i' == "Not at all democratically":how_democ`i' 
	replace how_democ = 2 if how_democ`i' == "Not too democratically":how_democ`i'
	replace how_democ = 3 if how_democ`i' == "Mostly democratically":how_democ`i'
	replace how_democ = 4 if how_democ`i' == "Completely democratically":how_democ`i'
}

label variable how_democ "How democratic is the US" 
label define how_democl 1 "Not at all", replace
label define how_democl 2 "Not too", add
label define how_democl 3 "Mostly", add
label define how_democl 4 "Completely", add
label values how_democ how_democl

drop overallhowdemocraticallydoyouthi v49 how_democ1 how_democ2



*----------------------------*
* 8.) Post-demographics      *
*----------------------------*

drop age

/* Gender */
rename gender Gender
tab Gender
gen gender_post = .
replace gender_post = 1 if regexm(Gender, "Female")
replace gender_post = 2 if regexm(Gender, "Male")

label variable gender_post "Gender (post-survey)"
label define genderl 1 "Female", replace
label define genderl 2 "Male", add
label values gender_post genderl
drop Gender

/* Income */
sencode householdincome, generate(income) 
tab income
gen hh_income = .
replace hh_income = 1 if income == "$0-$9,999":income
replace hh_income = 2 if income == "$10,000-$24,999":income
replace hh_income = 3 if income == "$25,000-$49,999":income
replace hh_income = 4 if income == "$50,000-$74,999":income
replace hh_income = 5 if income == "$75,000-$99,999":income
replace hh_income = 6 if income == "$100,000-$124,999":income
replace hh_income = 7 if income == "$125,000-$149,999":income
replace hh_income = 8 if income == "$150,000-$174,999":income
replace hh_income = 9 if income == "$175,000-$199,999":income
replace hh_income = 10 if income == "$200,000+":income
replace hh_income = 11 if income == "Prefer not to answer":income

label variable  hh_income "Household income" 
label define incl 1 "\$0-\$9,999", replace
label define incl 2 "\$10,000-\$24,999", add
label define incl 3 "\$25,000-\$49,999", add
label define incl 4 "\$50,000-\$74,999", add
label define incl 5 "\$75,000-\$99,999", add
label define incl 6 "\$100,000-\$124,999", add
label define incl 7 "\$125,000-\$149,999", add
label define incl 8 "\$150,000-\$174,999", add
label define incl 9 "\$175,000-\$199,999", add
label define incl 10 "\$200,000+", add
label define incl 11 "Prefer not to answer", add
label values hh_income incl
drop householdincome income

/* order */
order region devicetype, last

/* save */
saveold "data/outputs/clean_mm.dta", replace 



*-------------------------------------------*
* 9.) Merge in Experiment-2 Treatments      *
*--------------------------------------------*

/* Read in the data that gives randomization */ 
*import delimited "data/inputs/PageOrder.csv", /*
*/       encoding(ISO-8859-1) clear
*rename v1 respondentid 
use "data/inputs/PageOrder.dta" 


merge 1:1 respondentid using "data/outputs/clean_mm.dta"
drop if _merge == 1
drop _merge

/* Create an assignment variable for experiment 2 randomization 
v12 == 15 & 16: "Dem, no pushback"
v12 == 17 & 18: "Rep, no pushback"
v12 == 19: "Dem, voter protest"
v12 == 20: "Dem, lawsuit" 
v12 == 21 & 22: "Dem, successful"
v12 == 23: "Rep, voter protest"
v12 == 24: "Rep, lawsuit" 
v12 == 25 & 26: "Rep, successful" */ 


/* What Type of Vignette Did Respondent See? */ 
gen exp2_scenario = . 
replace exp2_scenario = 0 if v12 >= 15 & v12 <= 18
replace exp2_scenario = 1 if v12 == 19 | v12 == 23  
replace exp2_scenario = 2 if v12 == 20 | v12 == 24   
replace exp2_scenario = 3 if (v12 >= 21 & v12 <= 22) | (v12 >= 25 & v12 <= 26) 
label define exp2_scenariol 0 "No Pushback" 1 "Voter Protest" 2 "Lawsuit" /*
*/ 3 "Successful Appointment", replace
label values exp2_scenario exp2_scenariol

tab v12 if missing(exp2_scenario)

/* What Party Was Your Governor? */ 
gen exp2_party = . 
replace exp2_party = 0 if (v12 >= 15 & v12 <= 16) | (v12 >= 19 & v12 <= 22)
replace exp2_party = 1 if (v12 >= 17 & v12 <= 18) | (v12 >= 23 & v12 <= 26)
label define exp2_partyl 1 "Republican Governor" /*
*/ 0 "Democratic Governor", replace
label values exp2_party exp2_partyl

tab v12 if missing(exp2_party)

drop v2-v19


/* Did partisanship of governor in vignette match own partisanship? */
gen copartisan = .
replace copartisan = 1 if (party3 == 1 | party7 <= 3) & exp2_party == 0
replace copartisan = 0 if (party3 == 1 | party7 <= 3) & exp2_party == 1
replace copartisan = 0 if (party3 == 3 | party7 >= 5) & exp2_party == 0
replace copartisan = 1 if (party3 == 3 | party7 >= 5) & exp2_party == 1

label variable copartisan "Governor in vignette"
label define copartisanl 1 "Co-partisan", replace
label define copartisanl 0 "Not co-partisan", add
label values copartisan copartisanl
tab1 copartisan exp2_support exp2_consistent


/* save */
saveold "data/outputs/clean_mm.dta", replace 


/* end */
